package kr.ac.konkuk.db.quadtree.node;

import java.util.Collection;
import java.util.Set;

import kr.ac.konkuk.db.quadtree.RowKey;
import kr.ac.konkuk.db.quadtree.callback.GeometryProvider;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;

public abstract class NodeBase {
	public static final int LEFT_BOTTOM_INDEX = 0;
	public static final int RIGHT_BOTTOM_INDEX = 1;
	public static final int LEFT_TOP_INDEX = 2;
	public static final int RIGHT_TOP_INDEX = 3;
	
	protected int index;
	protected Coordinate center;
	protected Envelope env;
	protected String cf;
	protected GeometryProvider geometryProvider;
	
	public NodeBase(String cf, Envelope env, GeometryProvider provider) {
		this.cf = cf;
		this.env = env;
		this.center = this.env.centre();
		this.geometryProvider = provider;
	}
	
	public Envelope env() {
		return env;
	}
	
	public String columnFamily() {
		return cf;
	}
	
	public abstract void put(RowKey rowKey, Coordinate coord, Set<String> cfSet);
	public abstract void search(Envelope searchEnv, NodeVisitor visitor);
	public abstract Collection<Coordinate> remove(RowKey rowKey, Coordinate coord);
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[cf=")
			.append(cf)
			.append(", center=")
			.append(center)
			.append(", env=")
			.append(env)
			.append(']');
		
		return sb.toString();
	}
	
	public String toString(int level) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0 ; i < level ; ++i) {
			sb.append("  ");
		}
		sb.append(toString());
		
		return sb.toString();
	}
}
